package com.demo;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Room  implements ApplicationContextAware {
    public int RId;
    public String RNo;
    public double RPrice;
    public Person RPerson;
    public ApplicationContext ctx;
    public void setRPerson(Person RPerson) {
        this.RPerson = RPerson;
    }

    public int getRId() {
        return RId;
    }

    public void setRId(int RId) {
        this.RId = RId;
    }

    public String getRNo() {
        return RNo;
    }

    public void setRNo(String RNo) {
        this.RNo = RNo;
    }

    public double getRPrice() {
        return RPrice;
    }

    public void setRPrice(double RPrice) {
        this.RPrice = RPrice;
    }

    @Override
    public String toString() {
        return "Room{" +
                "RId=" + RId +
                ", RNo='" + RNo + '\'' +
                ", RPrice=" + RPrice +
                ", RPerson=" + RPerson.toString() +
                '}';
    }


    @Override
    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        this.ctx = ctx;
    }
    public void sendMessageToPerson(String name, String text) {
        if (RPerson.pName.equals(name)) {
            PersonListEvent event = new PersonListEvent(this,RPerson,text);
            //ApplicationEvent发布到ApplicationContext  将一个实现了ApplicationEvent的自定义事件类作为参数  同步接收
            ctx.publishEvent(event);
            return;
        }
    }
}
